package com.film.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.film.po.FilmInfo;
import com.film.service.FilmInfoService;

/**
 * 电影信息
 * @author Administrator
 *
 */
@RestController
public class FilmInfoController{

	//电影信息service
	private FilmInfoService filmInfoService;
	
	@Autowired
	public void setFilmInfoService(FilmInfoService filmInfoService) {
		this.filmInfoService = filmInfoService;
	}

	/**
	 * 添加
	 * @param filmInfo
	 * @return
	 */
	@RequestMapping(value="/filminfo",method=RequestMethod.POST)
	public ResponseEntity<FilmInfo> add(@RequestBody FilmInfo filmInfo) {
		try {
			FilmInfo filmInfo2 = filmInfoService.add(filmInfo);
			
			return new ResponseEntity<FilmInfo>(filmInfo2,HttpStatus.CREATED);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<FilmInfo>(HttpStatus.CONFLICT);
		
	}

	/**
	 * 根据id删除 
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/filminfo/{id}",method=RequestMethod.DELETE)
	public ResponseEntity<Void> deleteById(@PathVariable("id") int id) {
		try {
			filmInfoService.deleteById(id);
			return new ResponseEntity<Void>(HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
		
	}

	/**
	 * 更新
	 * @param filmInfo
	 * @return
	 */
	@RequestMapping(value="/filminfo",method=RequestMethod.PUT)
	public ResponseEntity<FilmInfo> update(@RequestBody FilmInfo filmInfo) {
		try {
			FilmInfo filmInfo2 = filmInfoService.update(filmInfo);
			return new ResponseEntity<FilmInfo>(filmInfo2,HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<FilmInfo>(HttpStatus.NOT_FOUND);
		
	}

	/**
	 * 根据id查
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/filminfo/{id}",method=RequestMethod.GET)
	public ResponseEntity<FilmInfo> findById(@PathVariable("id") int id) {
		try {
			FilmInfo filmInfo = filmInfoService.findById(id);
			return new ResponseEntity<FilmInfo>(filmInfo,HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<FilmInfo>(HttpStatus.NOT_FOUND);
		
	}

	/**
	 * 查询所有
	 * @return
	 */
	@RequestMapping(value="/filminfos",method=RequestMethod.GET)
	public ResponseEntity<List<FilmInfo>> getList() {
		try {
			List<FilmInfo> list = filmInfoService.getList();
			return new ResponseEntity<List<FilmInfo>>(list,HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<List<FilmInfo>>(HttpStatus.NO_CONTENT);
		
	}
	
	/**
	 * 根据参数查
	 * @return
	 */
	@RequestMapping(value="/filminfos/param",method=RequestMethod.POST)
	public ResponseEntity<List<FilmInfo>> selectFilmInfoByParam(@RequestBody FilmInfo filmInfo) {
		try {
			List<FilmInfo> list = filmInfoService.selectFilmInfoByParam(filmInfo);
			return new ResponseEntity<List<FilmInfo>>(list,HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<List<FilmInfo>>(HttpStatus.NO_CONTENT);
		
	}

	/**
	 * 根据类别id查所有
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/filminfo/filmtype/{id}",method=RequestMethod.GET)
	public ResponseEntity<List<FilmInfo>> getListByFilmTypeId(@PathVariable("id") int id) {
		try {
			List<FilmInfo> list = filmInfoService.getListByFilmTypeId(id);
			return new ResponseEntity<List<FilmInfo>>(list,HttpStatus.OK);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new ResponseEntity<List<FilmInfo>>(HttpStatus.NO_CONTENT);
		
	}
	

}
